package com.zjjk.transfer.source.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.zjjk.transfer.source.entity.SourceDish;
import com.zjjk.transfer.source.mapper.SourceDishMapper;
import com.zjjk.transfer.source.service.SourceDishService;
import com.zjjk.transfer.source.param.SourceDishPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 餐品 服务实现类
 *
 * @author xuziyang
 * @since 2021-03-26
 */
@Slf4j
@Service
@DS("source")
public class SourceDishServiceImpl extends BaseServiceImpl<SourceDishMapper, SourceDish> implements SourceDishService {

    @Autowired
    private SourceDishMapper sourceDishMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveSourceDish(SourceDish sourceDish) throws Exception {
        return super.save(sourceDish);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateSourceDish(SourceDish sourceDish) throws Exception {
        return super.updateById(sourceDish);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteSourceDish(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<SourceDish> getSourceDishPageList(SourceDishPageParam sourceDishPageParam) throws Exception {
        Page<SourceDish> page = new PageInfo<>(sourceDishPageParam, OrderItem.desc(getLambdaColumn(SourceDish::getCreateTime)));
        LambdaQueryWrapper<SourceDish> wrapper = new LambdaQueryWrapper<>();
        IPage<SourceDish> iPage = sourceDishMapper.selectPage(page, wrapper);
        return new Paging<SourceDish>(iPage);
    }

}
